//订单支付页面


Page({
  //当前页面的数据
  data: {
    order_mun: '',
    orderAmount: 0.00,
    type: '',
    couponid:0,
    dianzan_status:0,
    op:'',
    userid:''
  },

  //初始化加载
  onLoad: function (options) {
    var data = JSON.parse(options.data);
    var dianzan_status = data.dianzan_status;
    var obj = {
      order_mun: data.order_mun,
      orderAmount: data.totalPrice,
      type: data.type,
      couponid: data.couponid ? data.couponid : 0,
      dianzan_status: dianzan_status,
      userid: getApp().globalData.id,
    }
    this.setData(obj);
    getApp().globalData.orderfukuan = obj;

  },

  //获取支付类型
  getPaymentType: function () {
    var page = this;
    app.api.getPaymentType(function (res) {
      if (res.status) {
        page.setData({
          paymentType: res.data
        });
      } else {
        app.common.errorToBack('获取支付方式失败');
      }
    });
  },

  //微信支付触发
  wechatPay: function () {
    var that =this
    wx.login({
      success: function (res) {
        if (res.code) {
          wx.request({
            url: 'https://wukongweixiu.cn/index/Wxpay/sendCode',
            data: {
              code: res.code,
              order_mun: that.data.order_mun,
              orderAmount: that.data.orderAmount,
              type:1,
              couponid: that.data.couponid,
            },
            method: 'GET',
            success: function (res) {
              if (res.data.totalPrice =0){
                wx.showToast({
                  title: '',
                })
                wx.navigateTo({
                    url: '../order/order'
                  });
                return false;
              }
              wx.requestPayment({
                timeStamp: res.data.timeStamp,
                nonceStr: res.data.nonceStr,
                package: res.data.package,
                signType: 'MD5',
                paySign: res.data.paySign,
                success: function (res) {
                  //支付成功修改订单状态
                  wx.request({
                    url: 'https://wukongweixiu.cn/index/Order/notify',
                    data: getApp().globalData.orderfukuan,
                    method: 'GET',
                    success: function (resnotify) {
                      wx.showToast({
                        title: resnotify.data.msg,
                      })
                      wx.navigateTo({
                        url: '../order/order'
                      });
                    }
                  })

                },
                fail: function (res) {

                  // wx.navigateTo({
                  //   url: '../order/order'
                  // });
                }
              })
            }
          })
        } else {

        }
      }
    });
  },

  //线下支付触发
  offline: function () {
    // var page = this;
    // wx.showModal({
    //   title: '线下支付说明',
    //   content: '请联系客服进行线下支付',
    //   cancelText: '订单详情',
    //   confirmText: '继续购物',
    //   success: function (res) {
    //     if (res.confirm) {
    //       wx.switchTab({
    //         url: '/pages/index/index'
    //       });
    //     } else if (res.cancel) {
    //       wx.redirectTo({
    //         url: '../../member/order/orderDetail/orderDetail?order_id=' + page.data.orderId
    //       });
    //     }
    //   }
    // });
  },
});